<?php
/**
 * ExtFormPanelBase class file
 *
 * @author TrueSoftware B.V. (The Netherlands)
 * @link http://www.ext4yii.com
 * @copyright Copyright 2007-2010 TrueSoftwareB.V. all rights reserved.
 * @license http://www.ext4yii.com/license/
 *          EVALUATION VERSION - NOT FOR COMMERCIAL USE OR DISTRIBUTION.
 * @version 0.7.2
 */
class ExtFormPanelBase extends ExtPanel
{
    private $_form_class_types = array('ExtBasicForm');

    public function parseNode(ExtHTMLParserNode $node,
            ExtASTWalker $astwalker)
    {
        $this->setFormControl($node);
        parent::parseNode($node, $astwalker);
        if($this->parseForm($node, $astwalker))
            $this->setJavaScriptConfig ('convertBaseParamsToHiddenFields',
                'function(){ext4yii.formConvertBaseParamsToHiddenFields("'. $this->getId() .'")}');
    }

    private function parseForm($node,$astwalker)
    {
        $form = $node->findPropertyByName('form');
        if(!is_null($form))
        {
            $items=parent::parseNodeWidthTag($form,
                    $astwalker,
                    true,
                    null,
                    $this,
                    $this->_form_class_types);
            $form->shiftUp();
            return true;
        }
        return false;
    }

    private function setFormControl($root)
    {
        foreach($root->children as $node)
        {
            $this->setFormControl($node);
            if(!is_null($node->extctl) && 
                !($node->extctl instanceof ExtBasicForm) &&
                ($node->extctl instanceof ExtObservable))
            {
                $node->extctl->setJavaScriptConfig('getForm','function(){return Ext.getCmp("'.$this->getId().'").getForm(); }');
                $node->extctl->setJavaScriptConfig('getFormPanel','function(){return Ext.getCmp("'.$this->getId().'"); }');
            }
        }
    }
}
?>
